using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace web
{
    class OtherSet
    {
        public void colseComputer(Form1 obj)
        {
            CloseWin closewin = new CloseWin();
            closewin.ShowDialog(obj);
            if (closewin.DialogResult == DialogResult.OK)
            {
                string n = closewin.get_time();
                int i = (Convert.ToInt16(n) * 60);
                n = i.ToString();
                closewin.Close();
                System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
                myProcess.StartInfo.FileName = "cmd.exe";
                myProcess.StartInfo.UseShellExecute = false;
                myProcess.StartInfo.RedirectStandardInput = true;
                myProcess.StartInfo.RedirectStandardOutput = true;
                myProcess.StartInfo.RedirectStandardError = true;
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();
                myProcess.StandardInput.WriteLine("shutdown -f -s -t " + n);
            }

        }

        public void colseComputer_2()
        {
            System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
            myProcess.StartInfo.FileName = "cmd.exe";
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.RedirectStandardInput = true;
            myProcess.StartInfo.RedirectStandardOutput = true;
            myProcess.StartInfo.RedirectStandardError = true;
            myProcess.StartInfo.CreateNoWindow = true;
            //myProcess.StartInfo.CreateNoWindow
            myProcess.Start();
            myProcess.StandardInput.WriteLine("shutdown -i");
        }

        public void other_user()
        {
            System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
            myProcess.StartInfo.FileName = "cmd.exe";
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.RedirectStandardInput = true;
            myProcess.StartInfo.RedirectStandardOutput = true;
            myProcess.StartInfo.RedirectStandardError = true;
            myProcess.StartInfo.CreateNoWindow = true;
            myProcess.Start();
            myProcess.StandardInput.WriteLine("shutdown -l");

        }

        public void reset()
        {
            System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
            myProcess.StartInfo.FileName = "cmd.exe";
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.RedirectStandardInput = true;
            myProcess.StartInfo.RedirectStandardOutput = true;
            myProcess.StartInfo.RedirectStandardError = true;
            myProcess.StartInfo.CreateNoWindow = true;
            myProcess.Start();
            myProcess.StandardInput.WriteLine("shutdown -r");

        }

        public void cancelCloseComputer()
        {
            System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
            myProcess.StartInfo.FileName = "cmd.exe";
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.RedirectStandardInput = true;
            myProcess.StartInfo.RedirectStandardOutput = true;
            myProcess.StartInfo.RedirectStandardError = true;
            myProcess.StartInfo.CreateNoWindow = true;
            myProcess.Start();
            myProcess.StandardInput.WriteLine("shutdown -a");
        }

        public void openRegedit()
        {
            System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
            myProcess.StartInfo.FileName = "regedit";
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.RedirectStandardInput = true;
            myProcess.StartInfo.RedirectStandardOutput = true;
            myProcess.StartInfo.RedirectStandardError = true;
            myProcess.StartInfo.CreateNoWindow = false;
            myProcess.Start();
            //myProcess.StandardInput.WriteLine("regedit");
        }

        public void openStart()
        {
            System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
            myProcess.StartInfo.FileName = "msconfig";
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.RedirectStandardInput = true;
            myProcess.StartInfo.RedirectStandardOutput = true;
            myProcess.StartInfo.RedirectStandardError = true;
            myProcess.StartInfo.CreateNoWindow = true;
            myProcess.Start();
            //myProcess.StandardInput.WriteLine("regedit");
        }

        public void runStart(string name,bool boolIs)
        {
            string runPath="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
            RegistryKey ms_run = Registry.LocalMachine.OpenSubKey(runPath, true);
            if(ms_run==null)
            {
                ms_run=Registry.LocalMachine.CreateSubKey(runPath);
            }
            if (boolIs==true)
            {
                ms_run.SetValue(name, Application.ExecutablePath.ToString());
            }
            else
            {
                if (ms_run.GetValue(name)!=null)
                {
                    //Registry.LocalMachine.(Microsoft.Win32.Registry.LocalMachine + "\\" + runPath + "\\" + name);
                    ms_run.SetValue(name,"");
                }
            }
        }
    }
}
